home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / _TR_HTOL.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  739b  |  39 lines

  1. /*********
  2. *
  3. * _TR_HTOL.C
  4. *
  5. * by Ralph Davis
  6. *
  7. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  8. *
  9. * SYNTAX:  _tr_htol(cp)
  10. *          char *cp;
  11. *
  12. * RETURN:  long integer equivalent of cp
  13. *
  14. *********/
  15.  
  16. #include "trlib.h"
  17.  
  18. long _tr_htol(s)  /* dec() internal function */
  19. char *s;
  20. {
  21.    int hexdigit, i;
  22.    long n;
  23.  
  24.    n = 0L;
  25.    for (i = 0; i < _tr_strlen(s); i++)
  26.    {
  27.       if (s[i] >= '0' && s[i] <= '9')
  28.           hexdigit = s[i] - '0';
  29.       else if (s[i] >= 'a' && s[i] <= 'f')
  30.           hexdigit = s[i] - 'a' + 10;
  31.       else if (s[i] >= 'A' && s[i] <= 'F')
  32.           hexdigit = s[i] - 'A' + 10;
  33.       else
  34.           return(0L);
  35.       n = 16 * n + hexdigit;
  36.    }
  37.    return(n);
  38. }
  39.